Skip to content

Fix ICE and type mismatch with array type aliases and const generics#7638

Open
Dnreikronos wants to merge 4 commits into
FuelLabs:masterfrom
Dnreikronos:fix/type-alias-array-const-generics-ice
Open

Fix ICE and type mismatch with array type aliases and const generics#7638
Dnreikronos wants to merge 4 commits into
FuelLabs:masterfrom
Dnreikronos:fix/type-alias-array-const-generics-ice

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Summary

  • Fix ICE "Const generic not materialized" when type aliases for arrays (e.g. type ArrayU8Len2 = [u8; 2]) are used as struct fields and compared via ==
  • extract_type_parameters now extracts const generic length parameters from array types (e.g. N → 2), matching the existing pattern used for Enum/Struct const generics
  • MaterializeConstGenerics for TypeId now handles TypeInfo::Alias by recursing into the aliased type, consistent with the existing Ref handling

Test plan

  • New e2e test type_alias_array_const_generics covering:
    • Struct fields typed as array aliases
    • Nested array aliases ([ArrayU8Len2; 3])
    • Equality comparison triggering Eq trait const generic path
    • Vec<Alias>::get().unwrap() return type resolution
  • All existing type_alias* tests pass (11/11)
  • All existing const_generic* tests pass (3/3)
  • All existing array* tests pass (18/18)

Closes #7616

extract_type_parameters ignored array lengths when matching concrete
arrays against generic impls like [T; N], so N was never mapped to its
literal value. Additionally, MaterializeConstGenerics did not recurse
through TypeInfo::Alias, stopping materialization at the alias boundary.

Closes FuelLabs#7616
Covers struct fields typed as array aliases, nested aliases, equality
via the Eq trait, and Vec<Alias>::get().unwrap() return type resolution.
@Dnreikronos Dnreikronos requested a review from a team as a code owner May 26, 2026 18:06
@fuel-cla-bot
Copy link
Copy Markdown

fuel-cla-bot Bot commented May 26, 2026

Thanks for the contribution! Before we can merge this, we need @Dnreikronos to sign the Fuel Labs Contributor License Agreement.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 26, 2026

PR Summary

Medium Risk
Touches core type-system unification and const-generic materialization paths used by traits and generics; scope is narrow but compiler-critical.

Overview
Fixes compiler crashes and wrong types when array length type aliases (e.g. type ArrayU8Len2 = [u8; 2]) appear in structs, equality, and generic APIs.

TypeId::materialize_const_generics now treats TypeInfo::Alias like refs: it materializes on the inner type and rebuilds the alias, so const lengths behind aliases are not left ambiguous.

extract_type_parameters for TypeInfo::Array now records const-generic length bindings when the original side still has an ambiguous length variable and the other side has a concrete literal—aligning arrays with how struct/enum const generics are unified.

Adds e2e type_alias_array_const_generics (nested aliases, ==, Vec<Alias>::get).

Reviewed by Cursor Bugbot for commit 1559195. Bugbot is set up for automated code reviews on this repo. Configure here.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 4, 2026

Merging this PR will degrade performance by 10.39%

❌ 1 regressed benchmark
✅ 24 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
tokens_for_program 591.2 µs 659.7 µs -10.39%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Dnreikronos:fix/type-alias-array-const-generics-ice (1559195) with master (ac933ff)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE and wrong type mismatch error when using type aliases and traits implemented for const generics arrays

1 participant